const webpack = require('webpack')
const {merge} = require('webpack-merge')
const baseConfig = require('./webpack.common.js')
const {CleanWebpackPlugin} = require("clean-webpack-plugin")


module.exports = merge(baseConfig, {
  mode: 'development',
  devtool: 'eval-cheap-module-source-map',
  devServer: {
    hot: true,
    open: true,
  },

  module: {
    rules: [
      {
        //css文件处理
        test: /\.css?$/,
        //执行顺序从右到左
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.(js|vue)$/,
        use: "eslint-loader",
        enforce: "pre",
      },
      {
        test: /\.less?$/,
        use: ["vue-style-loader", "css-loader", "less-loader"],
      },
      {
        test: /\.vue$/,
        use: "vue-loader",
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: [["@babel/preset-env", { targets: "defaults" }]],
            plugins: ["@babel/plugin-proposal-class-properties"],
          },
        },
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        use: {
          loader: "url-loader",
          options: {
            limit: 10 * 1024,
            esModule: false,
          },
        },
      }
     
    ],
  },

  plugins: [
      //热更新
    new webpack.HotModuleReplacementPlugin(),
    // 清除之前包
    new CleanWebpackPlugin()
  ]
})